<template>
  <svg :class="svgClass" v-bind="$attrs" :style="svgStyle">
    <use :xlink:href="iconName" />
  </svg>
</template>

<script setup>
import { defineProps, computed } from "vue"

const props = defineProps({
  name: {
    type: String,
    required: true,
  },
  color: {
    type: String,
    default: "",
  },
  width:{
    type: String,
    default: "",
  },
  height:{
    type: String,
    default: "",
  }
})
const iconName = computed(() => `#icon-${props.name}`)
const svgClass = computed(() => {
  if (props.name) {
    return `svg-icon icon-${props.name}`
  }
  return "svg-icon"
})
const svgStyle = computed(() => {
  return {
    color:props.color,
    width:`${props.width}px`,
    height:`${props.height}px`,
  }
})
</script>

<style lang='less'>
.svg-icon {
  width: 1em;
  height: 1em;
  fill: currentColor;
  vertical-align: middle;
}
</style>